import 'package:flutter/material.dart';

class HomeNav extends StatefulWidget {
  const HomeNav({super.key});

  @override
  State<HomeNav> createState() => _HomeNavState();
}

class _HomeNavState extends State<HomeNav> {
  // 导航数据
  List navList = [
    {
      'title': '我的房屋',
      'icon': 'images/house_nav_icon@2x.png',
    },
    {
      'title': '我的报修',
      'icon': 'images/repair_nav_icon@2x.png',
    },
    {
      'title': '访客登记',
      'icon': 'images/visitor_nav_icon@2x.png',
    }
  ];
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 10, bottom: 10),
      padding: const EdgeInsets.only(bottom: 10, top: 10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children:
              // 方法1：使用循环生成结构体
              // [
              // for (var i = 0; i < navList.length; i++)
              //   Expanded(
              //       child: Column(
              //     children: [
              //       Image.asset(
              //         navList[i]['icon'],
              //         width: 35,
              //       ),
              //       Text(navList[i]['title']),
              //     ],
              //   ))
              // ],

              // 方法2：使用map方法将数据映射成结构体
              navList.map((item) {
            return Expanded(
                child: Column(children: [
              Image.asset(
                item['icon'],
                width: 35,
              ),
              Text(item['title']),
            ]));
          }).toList()
        ),
    );
  }
}
